package com.twu.biblioteca.model.item.books;

import com.twu.biblioteca.model.item.Item;
import com.twu.biblioteca.model.item.ItemFormatter;
import com.twu.biblioteca.model.item.ItemID;
import com.twu.biblioteca.model.item.ItemStatus;

/**
 * Created with IntelliJ IDEA.
 * User: cschlumb
 * Date: 08/08/2013
 * Time: 11:29
 * To change this template use File | Settings | File Templates.
 */
public class BookFormatter extends ItemFormatter {

    private final StringBuilder stringBuilder;

    public BookFormatter() {
        stringBuilder = new StringBuilder();
    }

    private void add(ItemID id, Book book, ItemStatus status) {
        stringBuilder.append("ID: ");
        stringBuilder.append(id.getId());
        stringBuilder.append('\t');
        stringBuilder.append("Title: ");
        stringBuilder.append(book.getTitle());
        stringBuilder.append('\t');
        stringBuilder.append("Author: ");
        stringBuilder.append(book.getAuthor());

        if (status.equals(ItemStatus.RESERVED)){
            stringBuilder.append("\t(");
            stringBuilder.append(status.name());
            stringBuilder.append(")");
        }
        stringBuilder.append("\n");
    }

    @Override
    public void add(ItemID id, Item item, ItemStatus status) {
        add(id, (Book) item, status);
    }

    @Override
    public String toFormattedString(){
        return stringBuilder.toString();
    }
}
